import 'package:flutter/material.dart';

class ChatTextInputView extends StatelessWidget {
  /// 文本控制器
  final TextEditingController? controller;

  /// 提示文字
  final String? hintText;

  /// 最大长度
  final int? maxLength;

  /// 输入文本改变回调
  final ValueChanged<String>? onChanged;

  /// 输入完成回调
  final VoidCallback? onEditingComplete;

  /// 输入完成回调
  final ValueChanged<String>? onSubmitted;

  /// 输入框左侧文本
  final Widget? prefixIcon;

  /// 输入框左侧文本约束
  final BoxConstraints? prefixIconConstraints;

  /// 键盘类型
  final TextInputType? keyboardType;

  /// 输入文本的样式
  final TextStyle? style;

  /// 提示文本的样式
  final TextStyle? hintStyle;

  /// 焦点节点
  final FocusNode? focusNode;

  const ChatTextInputView({
    super.key,
    this.maxLength = 20,
    this.controller,
    this.prefixIcon,
    this.prefixIconConstraints,
    this.onChanged,
    this.onEditingComplete,
    this.onSubmitted,
    this.keyboardType,
    this.style,
    this.hintStyle,
    this.focusNode,
    this.hintText,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      constraints: const BoxConstraints(
        minHeight: 35,
        maxHeight: 300,
      ),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(7),
        color: Colors.white,
      ),
      child: TextField(
        focusNode: focusNode,
        maxLines: null, // maxLines：null, 就能自适应高度了。
        maxLength: 200,
        cursorColor: const Color(0xff3BAB71),
        controller: controller,
        textAlignVertical: TextAlignVertical.center,
        keyboardType: keyboardType,
        textInputAction: TextInputAction.send,
        onChanged: onChanged,
        onEditingComplete: onEditingComplete,
        onSubmitted: onSubmitted,
        style: style ?? const TextStyle(color: Colors.black, fontSize: 16),
        decoration: InputDecoration(
          focusedBorder: const OutlineInputBorder(
            borderSide: BorderSide(
              width: 0,
              color: Colors.transparent,
            ),
          ),
          disabledBorder: const OutlineInputBorder(
            borderSide: BorderSide(width: 0, color: Colors.transparent),
          ),
          enabledBorder: const OutlineInputBorder(
            borderSide: BorderSide(width: 0, color: Colors.transparent),
          ),
          border: OutlineInputBorder(
            borderSide: BorderSide.none,
            borderRadius: BorderRadius.circular(7),
          ),
          hintText: hintText,
          prefixIcon: prefixIcon,
          prefixIconConstraints: prefixIconConstraints,
          hintStyle: hintStyle ?? const TextStyle(color: Color(0xffaaaaaa), fontSize: 16),
          counterText: '', // 取消文字计数器
          isDense: true,
          contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
          alignLabelWithHint: true,
        ),
      ),
    );
  }
}
